<template>
  <div>
    <h1>当前求和为：{{ $store.state.sum }}</h1>
    <h3 style="color:red">Person组件中的总人数是：{{ personList.length }}</h3>
    <select v-model.number="selectNum">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="incrementAdd">当前求和为奇数时再加</button>
    <button @click="incrementWait">等一等再加</button>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'CountCase',
  data () {
    return {
      selectNum: 1 // 用户选择的数字
    }
  },
  computed: {
    ...mapState(['personList'])
  },
  methods: {
    increment () {
      // this.$store.dispatch('jia', this.selectNum)
      // this.sum += this.selectNum
      this.$store.commit('JIA', this.selectNum)
    },
    decrement () {
      // this.$store.dispatch('jian', this.selectNum)
      // this.sum -= this.selectNum
      this.$store.commit('JIAN', this.selectNum)
    },
    incrementAdd () {
      this.$store.dispatch('jiaAdd', this.selectNum)
    },
    incrementWait () {
      this.$store.dispatch('jiaWait', this.selectNum)
    }
  }
}
</script>

<style scoped>
button {
    margin-left: 10px;
}
</style>
